<?php
session_start();
?>
<?php
if(!ob_start("ob_gzhandler")) ob_start();
?>
<html>
	<head>
		<title></title>
		<link rel = "stylesheet" type = "text/css" href = "mainFrame.css">
		<script type='text/javascript' src='jquery-1.7.js'></script>
		<script type = 'text/javascript' src = 'jquery-ui-1.8.16.custom.min.js'></script>
	</head>
		<body>
		<div style = "max-height:95%; overflow:auto;">
		<?php
	mysql_connect("localhost", "sapmenet_admin", "a1s2d3f4g5h6j7") or die ("Problem with datebase");
	mysql_select_db("sapmenet_users"); 
	if (isset($_SESSION['JID']))
	{
		$userID=$_SESSION['JID'];
		$currentID=$_SESSION['id'];
		if ($userID!=$currentID)
		{
			$id=$_SESSION['id'];
			//type albums for friends
		$albums=mysql_query("SELECT name, cover, ID FROM albums WHERE userID=$id");
		$newLine=0;
		
		
		while($theAlbum = mysql_fetch_array($albums, MYSQL_NUM))
			{
				$newLine++;
				if ($newLine>4)
				{
					echo ("<br>");
					$newLine=0;
				}
				echo ("<div id='$theAlbum[2]' class='album'><img src='$theAlbum[1]'><br>".$theAlbum[0]."</div>");
			}
		}
		else {
	
	
		//albums for me :D
		echo "<form action='createAlbum.php' method='post'>";
		echo "Create album: <input type='text' name='nameOfAlbum' id='createAlbumName'maxlength = '20'><input type='button' value='Create' id='createAlbumKopchi'> <input type = 'button' id = 'deleteAlbumKopchi' value = 'Delete album'><br>";
		$id=$_SESSION['JID'];
		$albums=mysql_query("SELECT name, cover, ID FROM albums WHERE userID=$id");
		$newLine=0;
		
		
		while($theAlbum = mysql_fetch_array($albums, MYSQL_NUM))
			{
				$newLine++;
				if ($newLine>4)
				{
					echo ("<br>");
					$newLine=0;
				}
				echo ("<div class = 'konceptualnoDivche'><div id='$theAlbum[2]' class='album'><img src='$theAlbum[1]'><br>".$theAlbum[0]."</div><img src = 'Icons/close.png' id = '$theAlbum[2]' title = 'Delete album' class = 'deleteAlbumHiddenButton'></div>");
			}
		}
	}
	else{
		header ('Location: ..\index.php');
		exit();
		}
	?>
		<script>
			$(".album").click(function()
			{
				$('input.text').removeClass('onFocus');
				$(this).addClass('onFocus');
				var theAlbumId = $(this).attr('id');
				$("#mainFrame").load("preview.php?album=" + theAlbumId);
			});
			$("#createAlbumKopchi").click(function()
			{
				var albumName = $("#createAlbumName").val();
				$.post("createAlbum.php", {nameOfAlbum : albumName}, function()
				{
					$("#mainFrame").load("albums.php");
				});
			});
			$("#deleteAlbumKopchi").click(function()
			{
				if($("#deleteAlbumKopchi").val()!="Hide delete buttons")
				{
					$(".deleteAlbumHiddenButton").css("display", "inline");
					$("#deleteAlbumKopchi").val("Hide delete buttons");
				}
				else
				{
					$(".deleteAlbumHiddenButton").css("display", "none");
					$("#deleteAlbumKopchi").val("Delete album");
				}
			});
			$(".deleteAlbumHiddenButton").click(function()
			{
				$(".deleteAlbumHiddenButton").removeClass("morgen");
				$(this).addClass("morgen");
				var theId = $(".morgen").attr("id");
				$.post("deleteAlbum.php", {albumID : theId}, function(data)
				{
					$("#mainFrame").load("albums.php");
				});
			});
		</script>
		</div>
		</body>
</html>	


































































